home *** CD-ROM | disk | FTP | other *** search
/ Mac Mania 6 / MacMania 6.toast / / Tools&Utilities / EnterAct Stuff / code to call Drag_ons / Call_Resource.c
C/C++ Source or Header  |  1996-05-24  |  37KB  |  1,205 lines

  1. /* Call_Resource.c: file to be added to any applications wishing to
  2. call the code resources that come with EnterAct.
  3. Note the other Call_Resource.c file on your source disk is adapted for use
  4. with Minimal App. */
  5.  
  6. /* Copyright © 1991 the Free Software Foundation, Inc.
  7.  *         This file is free software; you can redistribute or modify
  8.  * it under the terms of the GNU General Public License as published by
  9.  * the Free Software Foundation; either version 1, or any later version.
  10.  *         This file is distributed in the hope that it will be useful,
  11.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13.  * GNU General Public License for more details.
  14.  *         You should have received a copy of the GNU General Public License
  15.  * along with GAWK; see the file "COPYING hAWK". If not, write to
  16.  * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  17.  * Written for THINK C 4 on the Macintosh by Ken Earle (Dynabyte) Aug 1991.
  18.  */
  19.  
  20. /*
  21. REVISION May 96: who needs version flags in a prototype? There is just one
  22. format now for the CallResource() call. If you have been using CallResource()
  23. in your app, note the new prototype is
  24. void CallResource
  25.     (short        menuID,
  26.     short        item,
  27.     Boolean        concurrent,        // set FALSE if you don't support concurrent mode
  28.     char        *commandLineP    // -> complete command line or NULL
  29.     );
  30. Now your CallResource() will have the same arguments no matter which version
  31. you support. If you don't support concurrent operation (see below) then just
  32. set "concurrent" to FALSE. If you aren't passing in a command line, set
  33. commandLineP to NULL. If you want to support concurrent operation, you will
  34. still need to set VERSION2 TRUE as explained below. To pass a command line,
  35. put a pointer to a C string in commandLineP in the CallResource() call in
  36. your application (no changes needed here).
  37.  
  38. To call EnterAct-style code resources from your application:
  39. 1    Add a copy of this file to your app.
  40. 2    Call "InitCallResources()" in your startup code, just before
  41.     entering your event loop. The arguments are:
  42.     vRefNumForApp : preferably your application working directory, or 0
  43.     codeFolderName : preferably (Ptr)"\pDrag_on Modules"
  44.     menuID : the integer menu id of the menu you wish code resources
  45.         to be appended to. Preferably not File or Edit.
  46. 3    Call "CallResource()" to handle the code resources picked from
  47.     the menu you have added them to. Typically looks something like
  48.         #define    MenuInQuestion    261
  49.         void DoMenuInQuestionCommand(short item)
  50.             {
  51.             switch (item)
  52.                 {
  53.             case 1:
  54.                 DoItemOne();
  55.             break;
  56.             case 2:
  57.                 DoItemTwo();
  58.             break;
  59.             ...etc...
  60.             default:
  61.                 if (item > 0)
  62.                     CallResource(MenuInQuestion, item, T/F, cmdLineP/NULL);
  63.             break;
  64.                 }
  65.             }
  66. 4    Go through the extension ("callback") functions defined at the
  67.     bottom of this file, and decide which ones you wish to support.
  68.     You will probably not be able to support "InDictionary()", and
  69.     "GetNextMultiFile()" requires that your application keep a list
  70.     of files for some purpose or other (typically searching), but if
  71.     your application supports text files you should be able to provide
  72.     support for the others. Note "GetScreenHeight" and "GetScreenWidth"
  73.     are done here, no modification needed. The code resources supplied
  74.     with EnterAct can still do useful things even if no extensions are
  75.     supplied.
  76.     
  77.     If you decide not to support a particular extension, you need only
  78.     set the corresponding pointer to NULL in the function SetUpCodeCommunication().
  79.     For example, if you don't support InDictionary_Ext, then put
  80.         gacc.InDictionary_Ext = NULL;
  81.     in SetUpCodeCommunication().
  82.     
  83.     For more about the "DoEventLoopOnce()" callback, see 6 below.
  84.     
  85. 5    "ShowResult" and "SelectResult" defined below are called by
  86.     "CallResource" in response to a request by a code resource to display
  87.     the text results of the code resource run. If your application supports
  88.     TEXT documents, you should modify these functions to provide your
  89.     equivalents for these abilities. Otherwise, leave them as-is.
  90.  
  91. 6    Version 2 of hAWK (the one you received with this file) supports
  92.     concurrent execution. This means you fire up a hAWK program, go back
  93.     to working in your application (or even switch to some other app)
  94.     and hAWK notifies you when the program is done. There is a
  95.     penalty in speed of the hAWK program, usually far outweighed by
  96.     the benefit of being able to go back to work instantly rather than
  97.     having to sit there watching the watch cursor. Your calling application
  98.     should not be noticeably affected, except when the hAWK program
  99.     is doing something massive such as a huge "sort" or a large "copy".
  100.  
  101. The "VERSION2" defined constant just below should be set to TRUE if
  102. you wish to support concurrent execution of hAWK programs, FALSE
  103. if you do not. That's all that VERSION2 affects. Read Resource cannot
  104. run concurrently, and is not affected by the value of VERSION2.
  105.  
  106. To support concurrent exec of hAWK programs, follow these steps:
  107.     1    define VERSION2 just below to be TRUE
  108.     2    In the menu where you call Drag_on Modules, use
  109.         ...CallResource(MenuInQuestion, item, bool);
  110.         rather than just CallResource(MenuInQuestion, item);
  111.         -the "bool" variable is a Boolean, to be set to TRUE if
  112.         you want concurrent execution. Recommended interface is
  113.         to set this variable FALSE if the user has held down
  114.         either the <Shift> or <Option> key or both, and set it
  115.         TRUE otherwise.
  116.     3    One additional callback function needs to be provided,
  117.         in "DoEventLoopOnce()" below. Your callback should
  118.         have the form
  119.             extern void HandleOneEvent(void);
  120.         and can be a copy of your main event loop function,
  121.         except that it should handle just one event and then
  122.         return, and startup initializations if any can
  123.         be skipped (creating a region to track the mouse,
  124.         for example). If you use a global event record, you
  125.         can use the same global in your "HandleOneEvent"
  126.         function, but keep in mind that when "CallResource()"
  127.         returns, your global event record will reflect the
  128.         last event processed during your Drag_on Module run,
  129.         rather than the original menu call -- check what your
  130.         main event loop does with the event after the orginal
  131.         call, and verify that nothing important will be confused
  132.         by having the nature of the event changed during the
  133.         Drag_on Modules run.
  134.         (Note your event handler does not need to do any special
  135.         checking for the <Command><period> that stops hAWK.)
  136.     4    If your calling app is in the background when hAWK
  137.         finishes a run, a notice will be installed by the
  138.         DoNotify() routine below, flashing an icon in the
  139.         menu bar etc until you return to the calling app.
  140.         In your MAIN event handler (not the handle-one-event)
  141.         you should place the following bit of code to properly
  142.         handle the notify when your app resumes:
  143.             --declaration at the top of its file;
  144.                 -- to handle concurrent Drag_on Modules --
  145.                 Boolean gNotifying;
  146.                 Boolean gHawkIsRunning;
  147.                 NMRec    gNotifyRec;
  148.             
  149.             -- and in your main event handler, for the case of
  150.             "kSuspendResumeMessage";
  151.                 if (gNotifying)
  152.                     {
  153.                     NMRemove(&gNotifyRec);
  154.                     if (gNotifyRec.nmIcon)
  155.                         ReleaseResource(gNotifyRec.nmIcon);
  156.                     gNotifying = FALSE;
  157.                     ShowResultsAfterNotify();
  158.                     }
  159.         You will also need the standard global that records
  160.         whether or not your application is in the background,
  161.             Boolean gInBackground;
  162.         This variable should be set in your handle-one-event
  163.         function, and if your spelling of this variable name
  164.         differs from "gInBackground", change it here as well.
  165.         This file requires access to "gInBackground" in order
  166.         to determine if a notice should be posted at the end
  167.         of a hAWK program run.
  168.     5    In both your main event handler and the one-event
  169.         handler, calculate the "sleep" parameter for your
  170.         WaitNextEvent() call roughly as
  171.             gHawkIsRunning ? 2UL : GetCaretTime()
  172.         --adjust to suit your taste.
  173.     6    If you want the small icon "hAWK!" to flash for
  174.         notifications, move it to your application from "hAWK"
  175.         itself (it's just stored there).
  176.     7    One little wrinkle: what happens if you Quit your
  177.         application while hAWK is running? The recommended
  178.         solution here is to ask your user to issue a
  179.         <Command><period> to halt hAWK before proceeding
  180.         with the Quit. If you just pull the rug out from
  181.         under hAWK, files will probably be left open.
  182.         Sketchily:
  183.             Boolean DoQuit (...
  184.             extern Boolean gHawkIsRunning;...
  185.             if (gHawkIsRunning)
  186.                 {
  187.                 FlexAlert(justOK, stopIcon, "Please terminate your hAWK program \
  188.         with <Command><period> before quitting.");
  189.                 return(FALSE);
  190.                 }...
  191.  
  192. */
  193.  
  194. #include <string.h>
  195.  
  196. #ifndef NULL
  197. #define NULL        ((void *) 0)
  198. #endif
  199.  
  200. /* Change this to TRUE if you support concurrent hAWK - see above, point 6. */
  201. #define VERSION2 FALSE
  202.  
  203. #if VERSION2 == TRUE
  204. extern Boolean gInBackground;
  205. extern Boolean gNotifying;
  206. extern Boolean gHawkIsRunning;
  207. extern NMRec    gNotifyRec;
  208. #endif
  209.  
  210. /* Canned options, if you want to get going in a hurry:
  211. SUPPORT_LEVEL should be set to one of the following four options:
  212. MINIMAL - no extensions, no showing of results after a code resource run.
  213.     Note this doesn't mean the code resource won't be creating a text file,
  214.     it just means your application won't be showing it.
  215. RESULTSONLY - no extensions, but ability to show results supplied by you.
  216.     This means you should provide the hooks in ShowResult() and
  217.     SelectResult() - nothing else to do.
  218. BASICTEXT - in addition to providing the hooks in ShowResult() and
  219.     SelectResult(), fill in the blanks in GetFrontText() to allow the
  220.     code resource access to your front text window during a run.
  221. CUSTOMSUPPORT - ie avoid the above canned options.
  222.  
  223. There is one special case: if you support the "GetAppClip" extension,
  224. you’ll need to set SUPPORT_LEVEL to CUSTOMSUPPORT, and also
  225. define VERSION2 TRUE (getclip was not supported by version 1). NOTE this will
  226. also activate the PutAppClip extension. You must put your own function calls
  227. into GetAppClip and PutAppClip to make them functional.
  228. */
  229.  
  230.  
  231. #define MINIMAL            1
  232. #define RESULTSONLY        2
  233. #define BASICTEXT        3
  234. #define CUSTOMSUPPORT    4
  235.  
  236. /* Pick yer pleasure - from the above 4 options only, please. */
  237. #define SUPPORT_LEVEL MINIMAL
  238.  
  239. /* Struct passed to all code resources. Everything should be optional.
  240. "stdInFileName" is primarily for code resources that insist on having input
  241. from an existing file - hAWK, for example. "stdOutFileName", however, is
  242. handy for use by any code resource that creates text, as this file can be
  243. shown by the calling application */
  244. typedef struct AppCodeComm
  245.     {
  246.     // c strings except as noted
  247.     char        *stdInFileName,    // text from application to code resource
  248.                 *stdInFileNameP, // pascal version of above
  249.                 *stdOutFileName, // text from code resource to application
  250.                 *stdErrFileName, // error messages from code resource
  251.                 *callerName,     // the name of your application
  252.                 *thisCodeName;     // name of code resource being called
  253.     short            result;
  254.     short            version; // currently 1 or 2
  255. // Extension ("callback") functions - ALL OPTIONAL. These pointers-to-functions
  256. // are all set in  SetUpCodeCommunication() just before calling a code resource.
  257.     short            (*InDictionary_Ext)(char *tokenName);
  258.     Handle        (*GetFrontText_Ext)(Boolean getItAll);
  259.     void        (*GetNextMultiFile_Ext)(short *panePtr, short *indexPtr, 
  260.                 short *vRefNumPtr, char *fileName, Boolean clearFlag);
  261.     short         (*OKStopAlert_Ext)(Ptr cstringPtr);
  262.     void        (*MemoryAlert_Ext)(void);
  263.     short            (*GetScreenHeight_Ext)(void);
  264.     short            (*GetScreenWidth_Ext)(void);
  265.     void        (*ShowWatchCursor_Ext)(void);
  266. // Concurrent exec, added for version 2
  267.     void        (*DoEventLoopOnce_Ext)(void);
  268. // Access to scrap/clip of calling app
  269.     Handle        (*GetAppClip_Ext)(void);
  270. // Added for version 3
  271.     long        extendID; // Caller should set to 'VER3'
  272.     short        (*PutAppClip_Ext)(char *newClipStr);
  273. // End of callback functions.
  274. // Added for version 4
  275.     long        extend2ID; // Caller should set to 'VER4'
  276.     char        *commandLine;
  277.     } AppCodeComm, *ACCPtr;
  278.  
  279. static AppCodeComm    gacc;
  280.  
  281. /* Your application name goes here. */
  282. static char callerName[] = "MyApp";
  283.  
  284. typedef void (*CallCode)(ACCPtr ac);
  285.  
  286. static char *stdPathP;
  287.  
  288. typedef struct SpecificFolder
  289.     {
  290.     char     volName[32];
  291.     long    theDirID;
  292.     short        vRefNum;
  293.     } SpecificFolder;
  294. static SpecificFolder codeFolder;
  295.  
  296. /* Functions defined in this file: */
  297. /* Call this one towards the end of your startup, just before event loop */
  298. void InitCallResources(short vRefNumForApp, char *codeFolderName, short menuID);
  299. /* Called by InitCallResource: */
  300. void SetUpStandardFileNames(short vRefNum);
  301. void ShowResourcesInMenu(short vRefNumForApp, 
  302.     char *codeFolderName, short menuID);
  303. /* Two support routines for above */
  304. long FindCodeResFolder(short vRefNumForApp, char *codeFolderName);
  305. void AddCodesToMenu(long theDirID, short menuID);
  306. void OpenWDForCODE(void);
  307. /* Call this one in the "default" part of the switch for the
  308. menu containing the code resource names */
  309. void CallResource
  310.     (short        menuID,
  311.     short        item,
  312.     Boolean        concurrent,        // set FALSE if you don't support concurrent mode
  313.     char        *commandLineP    // -> complete command line or NULL
  314.     );
  315. #if VERSION2 == TRUE
  316. /* Enable/disable Drag_ons if running concurrently */
  317. void XableDrag_ons(short menuID, Boolean enable);
  318. /* Post a notify - NOTE this must be cleared by calling app */
  319. void DoNotify(void);
  320. /* For delayed showing of results */
  321. void ShowResultsAfterNotify(void);
  322. /* Beep and flush events */
  323. void AnnounceCompletion(void);
  324. #endif
  325.  
  326. /* Called by CallResource(), decide which extension functions to pass along */
  327. Boolean SetUpCodeCommunication(char *progName, char *commandLineP);
  328. /* Called by CallResource() to display results of resource run */
  329. Boolean ShowResult(char *name); /* either stdout or stderr */
  330. void SelectResult(void);
  331. /* A few support functions: */
  332. /* Pascal strings */
  333. void CopyPStr(Byte *srcStr, Byte *dstStr);
  334. void AppendPStr(Byte *s1, Byte *s2);
  335. Boolean PasEqualStrs(char *aStr, char *bStr);
  336. /* Files, names and locations */
  337. Byte *FullPathNameFromDirectory(long DirID, short vRefNum, Byte *s);
  338. Byte *FullPathNameFromVRefNum(short vRefNum, Byte *s);
  339. short    OpenWorkingDirectoryFromFullName(char *name, short len);
  340.  
  341. /* The extension functions - wrappers for your own calls */
  342. short InDictionary(char *tokenName);
  343. Handle GetFrontText(Boolean getItAll);
  344. void GetNextMultiFile(short *panePtr, short *indexPtr, 
  345.             short *vRefNumPtr, char *fileName, Boolean clearFlag);
  346. short OKStopAlert(Ptr cstringPtr);
  347. void MemoryAlert(void);
  348. short GetScreenHeight(void);
  349. short GetScreenWidth(void);
  350. void ShowWatchCursor(void);
  351. void DoEventLoopOnce(void);
  352. Handle GetAppClip(void);
  353. short PutAppClip(char *newClipStr);
  354.  
  355.  
  356.  
  357.  
  358. /* Call just before entering your event loop.
  359. Sets up full path names for standard in/out/err files,
  360. adds any code resources present to the menu of your choice.
  361. */
  362. void InitCallResources(short vRefNumForApp, char *codeFolderName, short menuID)
  363.     {
  364.     SetUpStandardFileNames(vRefNumForApp);
  365.     ShowResourcesInMenu(vRefNumForApp, codeFolderName, menuID);
  366.     }
  367.  
  368. /* Called once at beginning of application. Sets up full path names
  369. for std in/out/err files, and as a bonus sets gacc.callerName.
  370. The vRefNum passed in should be the application's vRefNum, but
  371. can be any old thing you want.
  372. -you can determine your application vrefnum at startup with
  373. short        appVRefNum;
  374. if (GetVol(NULL, &appVRefNum))
  375.     appVRefNum = 0;
  376.  */
  377. void SetUpStandardFileNames(short vRefNum)
  378.     {
  379.     if (!vRefNum)
  380.         GetVol(NULL, &vRefNum);
  381.     stdPathP = NewPtr(256);
  382.     if (MemError() != noErr)
  383.         goto PathTrouble;
  384.     gacc.stdInFileName = NewPtr(256);
  385.     if (MemError() != noErr)
  386.         goto PathTrouble;
  387.     gacc.stdInFileNameP = NewPtr(256);
  388.     if (MemError() != noErr)
  389.         goto PathTrouble;
  390.     gacc.stdOutFileName = NewPtr(256);
  391.     if (MemError() != noErr)
  392.         goto PathTrouble;
  393.     gacc.stdErrFileName = NewPtr(256);
  394.     if (MemError() != noErr)
  395.         goto PathTrouble;
  396.     if (vRefNum)
  397.         (void)(FullPathNameFromVRefNum(vRefNum, (Byte *)stdPathP));
  398.     else
  399.         stdPathP[0] = 0;
  400.     PtoCstr(stdPathP);
  401.     strcpy((Ptr)(gacc.stdInFileName), (Ptr)stdPathP);
  402.     strcpy((Ptr)(gacc.stdInFileNameP), (Ptr)stdPathP);
  403.     strcpy((Ptr)(gacc.stdOutFileName), (Ptr)stdPathP);
  404.     strcpy((Ptr)(gacc.stdErrFileName), (Ptr)stdPathP);
  405.     strcat((Ptr)(gacc.stdInFileName), "$tempStdIn");
  406.     strcat((Ptr)(gacc.stdInFileNameP), "$tempStdIn");
  407.     strcat((Ptr)(gacc.stdOutFileName), "$tempStdOut");
  408.     strcat((Ptr)gacc.stdErrFileName, "$tempStdErr");
  409.     CtoPstr((Ptr)(gacc.stdInFileNameP));
  410.     gacc.callerName = NewPtr(strlen(callerName)+1);
  411.     if (MemError() != noErr)
  412.         goto PathTrouble;
  413.     strcpy(gacc.callerName, callerName);
  414.     
  415.     return;
  416. PathTrouble:
  417.     OKStopAlert("Out of memory right at the start! \
  418. Blew the tubes trying to allocate standard file names.");
  419.     ExitToShell();
  420.     }
  421.  
  422. /* Index through folders in application's folder, looking for
  423. "\pDrag_on Modules". If found, index through files in folder and add
  424. any resource files found. */
  425. void ShowResourcesInMenu(short vRefNumForApp, 
  426.     char *codeFolderName, short menuID)
  427.     {
  428.     long    theDirID;
  429.     
  430.     if (theDirID = FindCodeResFolder(vRefNumForApp, codeFolderName))
  431.         AddCodesToMenu(theDirID, menuID);
  432.     }
  433.  
  434. long FindCodeResFolder(short vRefNumForApp, char *codeFolderName)
  435.     {
  436.     HFileInfo    myCPB;
  437.     WDPBRec        theParms;
  438.     char        fName[32];
  439.     long        theDirID;
  440.     short            index = 1, len;
  441.     OSErr        err;
  442.     
  443.     /* First extract "\pVolName:", volRef, and dirID for application folder */
  444.     theParms.ioNamePtr = (StringPtr)(codeFolder.volName);
  445.     theParms.ioVRefNum = vRefNumForApp;
  446.     theParms.ioWDIndex = 0;
  447.     theParms.ioWDProcID = 0;
  448.     theParms.ioWDVRefNum = 0;
  449.     if (PBGetWDInfo(&theParms,false))
  450.         return(0L);
  451.     len = codeFolder.volName[0];
  452.     codeFolder.volName[len + 1] = ':';
  453.     codeFolder.volName[0] = len + 1;
  454.     codeFolder.vRefNum = theParms.ioWDVRefNum;
  455.     theDirID = theParms.ioWDDirID;
  456.     
  457.     myCPB.ioNamePtr = (StringPtr)fName;
  458.     myCPB.ioVRefNum = vRefNumForApp;
  459.     do
  460.         {
  461.         myCPB.ioFDirIndex = index;
  462.         myCPB.ioDirID = theDirID;
  463.         if ((err = PBGetCatInfo(&myCPB, FALSE)) == noErr)
  464.             {
  465.             if (((myCPB.ioFlAttrib>>4) & 0x01) == 1) /* a folder */
  466.                 {
  467.                 if (PasEqualStrs(fName, codeFolderName))
  468.                     return(myCPB.ioDirID);
  469.                 }
  470.             }
  471.         ++index;
  472.         } while (err == noErr);
  473.     return(0L);
  474.     }
  475.  
  476. /* Search thru folder for code resources and add all codes to the menu. */
  477. void AddCodesToMenu(long theDirID, short menuID)
  478.     {
  479.     HFileParam     fp;
  480.     MenuHandle     theMenu;
  481.     char        fName[32];
  482.     short            index = 1;
  483.     OSErr        err;
  484.     Boolean        firstAdd = TRUE;
  485.     
  486.     theMenu = GetMHandle(menuID);
  487.     codeFolder.theDirID = theDirID;
  488.     fp.ioNamePtr = (StringPtr)fName;;
  489.     fp.ioVRefNum = codeFolder.vRefNum;
  490.     fp.ioFVersNum = 0;
  491.     do
  492.         {
  493.         fp.ioFDirIndex = index;
  494.         fp.ioDirID = codeFolder.theDirID;
  495.         if ((err = PBHGetFInfoSync((HParmBlkPtr)&fp)) == noErr)
  496.             {
  497.             if (fp.ioFlFndrInfo.fdType == 'rsrc'
  498.                 && fp.ioFlFndrInfo.fdCreator == 'RSED')
  499.                 {
  500.                 if (firstAdd)
  501.                     {
  502.                     AppendMenu(theMenu, "\p-");
  503.                     firstAdd = FALSE;
  504.                     }
  505.                 AppendMenu(theMenu, (StringPtr)fName);
  506.                 }
  507.             }
  508.         ++index;
  509.         } while (err == noErr);
  510.     /****** Open a working directory for the CODE folder: this is currently required
  511.     for hAWK, but will be eliminated for hAWK's next version. */
  512.     if (!firstAdd)
  513.         OpenWDForCODE();
  514.     }
  515.  
  516. /****** Open a working directory for the CODE folder: this is currently required
  517. for hAWK, but will be eliminated for hAWK's next version. */
  518. void OpenWDForCODE()
  519.     {
  520.     WDPBRec        theParms;
  521.     
  522.     theParms.ioCompletion = NULL;
  523.     theParms.ioVRefNum = codeFolder.vRefNum;
  524.     theParms.ioNamePtr = NULL;
  525.     theParms.ioWDDirID = codeFolder.theDirID;
  526.     theParms.ioWDProcID = 'ERIK';
  527.     if (!PBOpenWD(&theParms, FALSE)) /* IM IV pg 158 */
  528.         codeFolder.vRefNum = theParms.ioVRefNum;
  529.     }
  530.  
  531. /* The main event. Given a pick from your menu, load and call
  532. the resource. Display results if asked to by the resource.
  533. */
  534. void CallResource
  535.     (short        menuID,
  536.     short        item,
  537.     Boolean        concurrent,        // set FALSE if you don't support concurrent mode
  538.     char        *commandLineP    // -> complete command line or NULL
  539.     )
  540.     {
  541.     MenuHandle     theMenu;
  542.     Handle        rHdle;
  543.     CallCode    codeCaller;
  544.     char        codeNameString[64];
  545.     long        eof;
  546.     short        saveVol, refNum;
  547.     
  548.     theMenu = GetMHandle(menuID);
  549.     GetItem(theMenu, item, (StringPtr)codeNameString);
  550.     if (31 < (unsigned char)(codeNameString[0]))
  551.         {
  552.         /* An odd error: if the code resource was added to the menu during
  553.         startup, how can it have a name that is longer than a file name?
  554.         The assumption here is that we are calling something that is not a
  555.         code resource - either the wrong menu or an inappropriate item.
  556.         Uncomment the following alert if you want to double-check this.
  557.         
  558.         OKStopAlert("Code resource name is too long.");
  559.         */
  560.         return;
  561.         }
  562.     gacc.thisCodeName = NULL;
  563.     if (GetVol(NULL, &saveVol))
  564.         saveVol = 0;
  565.     SetVol(NULL, codeFolder.vRefNum);
  566.     /* See if there's enough memory to load the code resource
  567.     - the brute force approach, if anything more strict than necessary. */
  568.     if (HOpenRF(codeFolder.vRefNum, codeFolder.theDirID,
  569.                 (StringPtr)codeNameString, fsRdPerm, &refNum))
  570.         {
  571.         if (saveVol)
  572.             SetVol(NULL, saveVol);
  573.         OKStopAlert("Couldn't open the code resource.");
  574.         return;
  575.         }
  576.     if (GetEOF(refNum, &eof))
  577.         {
  578.         FSClose(refNum);
  579.         if (saveVol)
  580.             SetVol(NULL, saveVol);
  581.         OKStopAlert("Code resource seems damaged or empty - giving up.");
  582.         return;
  583.         }
  584.     FSClose(refNum);
  585.     rHdle = NewHandle(eof + eof/10); /* a guess */
  586.     if (MemError() != noErr)
  587.         {
  588.         if (saveVol)
  589.             SetVol(NULL, saveVol);
  590.         OKStopAlert("Not enough memory to proceed, sorry.");
  591.         return;
  592.         }
  593.     DisposHandle(rHdle);
  594.     rHdle = NULL;
  595.     if ((refNum = HOpenResFile(codeFolder.vRefNum, codeFolder.theDirID,
  596.                 (StringPtr)codeNameString, fsRdPerm)) != -1 && refNum
  597.                 && ResError() == noErr)
  598.         {
  599.         /* load CODE 0, set up extensions etc, lock down and call
  600.         -after, show results */
  601.         rHdle = Get1Resource ('CODE', 0);
  602.         if (!rHdle)
  603.             {
  604.             /* In error thinking it was a code resource - this really isn't fair */
  605.             CloseResFile(refNum);
  606.             if (saveVol)
  607.                 SetVol(NULL, saveVol);
  608.             OKStopAlert("CODE 0 from that resource file seems to be missing.");
  609.             return;
  610.             }
  611. #if VERSION2 == TRUE
  612.         gHawkIsRunning = TRUE;
  613.         XableDrag_ons(menuID, FALSE);
  614.         HiliteMenu(0);
  615. #endif
  616.         HLock(rHdle);
  617.         codeCaller = (CallCode)*rHdle;
  618.         SetUpCodeCommunication(codeNameString, commandLineP);
  619. #if VERSION2 == TRUE
  620.         if (!concurrent)
  621.             gacc.DoEventLoopOnce_Ext = NULL;
  622. #endif
  623.         codeCaller(&gacc);
  624.             
  625.         HUnlock(rHdle);
  626.         ReleaseResource(rHdle);
  627.         CloseResFile (refNum);
  628. #if VERSION2 == TRUE
  629.         XableDrag_ons(menuID, TRUE);
  630. #endif
  631.         }
  632.     else
  633.         OKStopAlert("Could not open the resource fork for that code resource.");
  634.     if (saveVol)
  635.         SetVol(NULL, saveVol);
  636.     /* Show any file requested */
  637.     /* results:
  638.     <= -3 : no action at present
  639.     -2 : show stderr
  640.     -1 : user cancelled or error during dialog - no run
  641.     0  : run OK, do nothing special after
  642.     1  : show stdout
  643.     2  : show and select stdout
  644.     > 2 : no action at present (counts as equivalent to 0)
  645.     */
  646.  
  647. #if VERSION2 == TRUE
  648.     if (!(gHawkIsRunning && gInBackground))
  649.         {
  650.         AnnounceCompletion();
  651.         }
  652.     if (gHawkIsRunning && gInBackground)
  653.         DoNotify();
  654.     else
  655. #endif
  656.  
  657.     if (gacc.result == -2)
  658.         ShowResult(gacc.stdErrFileName);
  659.     else if (gacc.result == 1 || gacc.result == 2)
  660.         {
  661.         if (ShowResult(gacc.stdOutFileName) && gacc.result == 2)
  662.             SelectResult();
  663.         }
  664.  
  665. #if VERSION2 == TRUE
  666.     gHawkIsRunning = FALSE;
  667. #endif
  668.  
  669.     /* A small cleanup after */
  670.     if (gacc.thisCodeName)
  671.         DisposPtr(gacc.thisCodeName);
  672.     }
  673.  
  674. #if VERSION2 == TRUE
  675. void XableDrag_ons(short menuID, Boolean enable)
  676.     {
  677.     MenuHandle menu = GetMHandle(menuID);
  678.     char    mText[64];
  679.     short        i;
  680.     
  681.     if (!menu) return;
  682.     i = CountMItems(menu);
  683.     GetItem(menu, i, mText);
  684.     while (i >= 1 && mText[1] != '-')
  685.         {
  686.         if (enable)
  687.             EnableItem(menu, i);
  688.         else
  689.             DisableItem(menu, i);
  690.         --i;
  691.         GetItem(menu, i, mText);
  692.         }
  693.     }
  694.  
  695. /* Post a notify. Beep, small icon, diamond beside calling app's name.
  696. NOTE when the calling app resumes, it should remove this notify and
  697. show results, with
  698.         if (gNotifying)
  699.             {
  700.             NMRemove(&gNotifyRec);
  701.             if (gNotifyRec.nmIcon)
  702.                 ReleaseResource(gNotifyRec.nmIcon);
  703.             gNotifying = FALSE;
  704.             ShowResultsAfterNotify();
  705.             }
  706. */
  707. void DoNotify()
  708.     {
  709.     OSErr nmError;
  710.     
  711.     if (!gInBackground) return;
  712.     gNotifyRec.qType = nmType;
  713.     gNotifyRec.nmMark = 1;
  714.     gNotifyRec.nmIcon = GetResource('SICN', 128); /* or NULL */
  715.     HNoPurge(gNotifyRec.nmIcon);
  716.     gNotifyRec.nmSound = (Handle)-1L;
  717.     gNotifyRec.nmStr = 0L;
  718.     gNotifyRec.nmResp = (NMProcPtr)0L;
  719.     gNotifyRec.nmRefCon = 0L;
  720.     
  721.     nmError = NMInstall(&gNotifyRec);
  722.     gNotifying = TRUE;
  723.     }
  724.  
  725. void ShowResultsAfterNotify()
  726.     {
  727.     if (gacc.result == -2)
  728.         ShowResult(gacc.stdErrFileName);
  729.     else if (gacc.result == 1 || gacc.result == 2)
  730.         {
  731.         if (ShowResult(gacc.stdOutFileName) && gacc.result == 2)
  732.             SelectResult();
  733.         }
  734.     FlushEvents(activMask+mDownMask+mUpMask, 0);
  735.     }
  736.  
  737. void AnnounceCompletion()
  738.     {
  739.     long    startTime, endTime;
  740.     
  741.     
  742.     SysBeep(2);
  743.     Delay(0L, &startTime);
  744.     endTime = startTime;
  745.     while (endTime - startTime < 50L)
  746.         Delay(0L, &endTime);
  747.     FlushEvents(62, 0);
  748.     }
  749.  
  750. #endif
  751.  
  752.  
  753. /* If you don't support some extensions, set the pointer for it to NULL here. */
  754. Boolean SetUpCodeCommunication(char *progName, char *commandLineP)
  755.     {
  756.     short    len;
  757. #if SUPPORT_LEVEL >= BASICTEXT
  758.     /* MyTextInFront(), which should return TRUE if one of your text
  759.     windows is in front or second from front (normally at the time of the call
  760.     the hAWK setup dialog will be the front window).
  761.     */
  762.     extern Boolean MyTextInFront(void);
  763. #if SUPPORT_LEVEL == CUSTOMSUPPORT
  764.     /* CanDoMultiFiles() should return TRUE if the user has selected
  765.     any files for multi-file operations, however you define that.
  766.     */
  767.     extern Boolean CanDoMultiFiles(void);
  768. #endif
  769. #endif
  770.     gacc.result = 0; /* clear before run - 0 means don't do anything after */
  771.     
  772. #if VERSION2 == TRUE
  773.     gacc.version = 2;
  774. #else
  775.     gacc.version = 1;
  776. #endif
  777.     
  778.     gacc.extendID = 0; // Set to 'VER3' if you support PutAppClip
  779.     /* Extensions, set up every run */
  780.     gacc.GetScreenHeight_Ext = GetScreenHeight;
  781.     gacc.GetScreenWidth_Ext = GetScreenWidth;
  782. #if SUPPORT_LEVEL >= MINIMAL && SUPPORT_LEVEL <= BASICTEXT
  783. #if SUPPORT_LEVEL == BASICTEXT
  784.     if (MyTextInFront())
  785.         gacc.GetFrontText_Ext = GetFrontText; /* MODIFY GetFrontText()! */
  786.     else
  787.         gacc.GetFrontText_Ext = NULL;
  788. #else
  789.         gacc.GetFrontText_Ext = NULL;
  790. #endif
  791.     gacc.InDictionary_Ext = NULL;
  792.     gacc.GetNextMultiFile_Ext = NULL;
  793.     gacc.OKStopAlert_Ext = NULL;
  794.     gacc.MemoryAlert_Ext = NULL;
  795.     gacc.ShowWatchCursor_Ext = NULL;
  796. #if VERSION2 == TRUE
  797.     gacc.DoEventLoopOnce_Ext = DoEventLoopOnce;
  798.     gacc.GetAppClip_Ext = NULL;
  799. #else
  800.     gacc.DoEventLoopOnce_Ext = NULL;
  801.     gacc.GetAppClip_Ext = NULL;
  802. #endif
  803. #else /* CUSTOMSUPPORT - check all extension functions below. */
  804.     gacc.InDictionary_Ext = InDictionary;
  805.     if (MyTextInFront())
  806.         gacc.GetFrontText_Ext = GetFrontText;
  807.     else
  808.         gacc.GetFrontText_Ext = NULL;
  809.     if (CanDoMultiFiles())
  810.         gacc.GetNextMultiFile_Ext = GetNextMultiFile;
  811.     else
  812.         gacc.GetNextMultiFile_Ext = NULL;
  813.     gacc.OKStopAlert_Ext = OKStopAlert;
  814.     gacc.MemoryAlert_Ext = MemoryAlert;
  815.     
  816.     gacc.ShowWatchCursor_Ext = ShowWatchCursor;
  817. #if VERSION2 == TRUE
  818.     gacc.DoEventLoopOnce_Ext = DoEventLoopOnce;
  819.     gacc.GetAppClip_Ext = GetAppClip;
  820.     gacc.extendID = 'VER3';
  821. #else
  822.     gacc.DoEventLoopOnce_Ext = NULL;
  823.     gacc.GetAppClip_Ext = NULL;
  824. #endif
  825. #endif
  826.     
  827.     if (gacc.extendID == 'VER3')
  828.         gacc.PutAppClip_Ext = PutAppClip;
  829.     else
  830.         gacc.PutAppClip_Ext = NULL;
  831.     
  832.     // Command line arg.
  833.     gacc.commandLine = commandLineP;
  834.     if (commandLineP != NULL)
  835.         {
  836.         gacc.extend2ID = 'VER4';
  837.         }
  838.     else
  839.         {
  840.         gacc.extend2ID = 0;
  841.         }
  842.     /* Set up code resource name for each call. */
  843.     len = progName[0];
  844.     gacc.thisCodeName = NewPtr(len+1);
  845.     if (MemError() != noErr)
  846.         return(FALSE); /* No big deal - but suggests code resource will
  847.                         run into trouble real quick if can't get 32 bytes
  848.                         now...*/
  849.     BlockMove(progName, gacc.thisCodeName, len);
  850.     gacc.thisCodeName[len] = '\0';
  851.     return(TRUE);
  852.     }
  853.  
  854. /* This function is called by CallResource() to display the TEXT result
  855. of a code resource run. If your application supports TEXT files, you will
  856. have a function that takes a file name and vRefNum as arguments, and displays
  857. the TEXT file in a window - that's the one to use.
  858.  
  859. A small but important complication: if the file is already being displayed
  860. in a window, your application should close it without asking to save
  861. changes, and then reread it from disk. Changes not saved, because these
  862. are temporary files needed for communication between the application and
  863. the code resource. */
  864. Boolean ShowResult(char *name)
  865.     {
  866. #if SUPPORT_LEVEL >= RESULTSONLY
  867.     short vrefnum;
  868.     char filename[32];
  869.     short len = strlen(name);
  870.     Ptr    endPtr = name + len, startPtr = endPtr;
  871.  
  872.     extern Boolean MyAppShowResult(short vRefNum, char *fileName);
  873.  
  874.  
  875.     while (startPtr >= name)
  876.         {
  877.         if (*startPtr == ':')
  878.             break;
  879.         --startPtr;
  880.         }
  881.     ++startPtr;
  882.     if (startPtr >= endPtr) return(FALSE);
  883.     filename[0] = endPtr - startPtr;
  884.     BlockMove(startPtr, filename+1, filename[0]);
  885.     
  886.     vrefnum = OpenWorkingDirectoryFromFullName(name, (short)(startPtr - name));
  887.     if (!vrefnum) return(FALSE);
  888.     return(MyAppShowResult(vrefnum, filename));
  889. #else
  890.     return(FALSE);
  891. #endif
  892.  
  893. /* For reference, the entire "MyAppShowResult" function for EnterAct is
  894.     if (wdPtr = IsFileOpen(fileName, vRefNum))
  895.         DoForcedCloseWindow(wdPtr);
  896.     return(DoOpenFile(text, FALSE, vRefNum, fileName));
  897. */
  898.  
  899.     }
  900.  
  901. /* This function should select all of the text in the front window, after
  902. checking that the front window is indeed a text window. */
  903. void SelectResult()
  904.     {
  905. #if SUPPORT_LEVEL >= RESULTSONLY
  906.     extern void MyAppSelectResult(void);
  907.     
  908.     MyAppSelectResult();
  909. #endif
  910.     }
  911.  
  912. /* Pascal strings */
  913.  
  914. /* Copy one pascal string to another */
  915. void CopyPStr(Byte *srcStr, Byte *dstStr)
  916.     {
  917.     long   srcLen = srcStr[0];
  918.  
  919.     BlockMove(srcStr, dstStr, srcLen + 1);
  920.     }
  921.  
  922. /* Append pascal s2 to pascal s1, avoiding overflow. */
  923. void AppendPStr(Byte *s1, Byte *s2)
  924.     {
  925.     short    s1Len = s1[0];
  926.     short    s2Len = s2[0];
  927.  
  928.     if (s1Len + s2Len > 255)
  929.         s2Len = 255 - s1Len;
  930.  
  931.     if (s2Len)
  932.         {
  933.         BlockMove (s2 + 1, s1 + s1Len + 1, s2Len);
  934.         s1Len += s2Len;
  935.         s1[0] = s1Len;
  936.         }
  937.     }
  938.  
  939. Boolean PasEqualStrs(char *aStr, char *bStr)
  940.     {
  941.     short i, lena = aStr[0], lenb = bStr[0];
  942.     
  943.     if (!lena || !lenb || lena != lenb)return(FALSE);
  944.     for (i = 1; i <= lena; ++i)
  945.         {
  946.         if (aStr[i] != bStr[i])
  947.             return(FALSE);
  948.         }
  949.     return(TRUE);
  950.     }
  951.  
  952. /* Files, names and locations */
  953.  
  954. /* NOTE the following two functions are based on examples supplied
  955. by Apple on one of their DTS disks - error checking has been added,
  956. and these versions are independent of the signed vs unsigned char
  957. controversy surrounding str255. Byte is defined in MacTypes.h
  958. for THINK C v4. */
  959.  
  960. /* Warning, these calls can fail! And why not? Everything else can... */
  961. /* Bug, these two are not for use by unix imitations such as A/UX. */
  962.  
  963. /* Construct "\pDisk:folder1:folder2:...folderN:" where folderN
  964. contains the file of interest. */
  965. Byte *FullPathNameFromDirectory(long DirID, short vRefNum, Byte *s)
  966.     {
  967.     CInfoPBRec    pb;
  968.     Byte        directoryName[256];
  969.  
  970.     s[0] = 0;
  971.     pb.dirInfo.ioNamePtr = (StringPtr)directoryName;
  972.     pb.dirInfo.ioDrParID = DirID;
  973.  
  974.     do 
  975.         {
  976.         pb.dirInfo.ioVRefNum = vRefNum;
  977.         pb.dirInfo.ioFDirIndex = -1;
  978.         pb.dirInfo.ioDrDirID = pb.dirInfo.ioDrParID;
  979.         if (PBGetCatInfo(&pb, FALSE))
  980.             {
  981.             break;
  982.             }
  983.         /* Append a colon  */
  984.         AppendPStr(directoryName, (Byte *)"\p:");
  985.         AppendPStr(directoryName, s);
  986.         CopyPStr(directoryName, s);
  987.         } while (pb.dirInfo.ioDrDirID != 2);
  988.     return(s);
  989.     }
  990.  
  991.  
  992. Byte *FullPathNameFromVRefNum(short vRefNum, Byte *s)
  993.     {
  994.  
  995.     WDPBRec    pb;
  996.  
  997.     pb.ioNamePtr = NULL;
  998.     pb.ioVRefNum = vRefNum;
  999.     pb.ioWDIndex = 0;
  1000.     pb.ioWDProcID = 0;
  1001.  
  1002.     if (PBGetWDInfo(&pb,false))
  1003.         {
  1004.         s[0] = 0;
  1005.         return(s);
  1006.         }
  1007.     return(FullPathNameFromDirectory(pb.ioWDDirID,pb.ioWDVRefNum,s));
  1008.     }
  1009.  
  1010. /* Determine working directory for file based on full path name. */
  1011. short    OpenWorkingDirectoryFromFullName(char *name, short len)
  1012.     {
  1013.     WDPBRec        theParms;
  1014.     OSErr     IOResult;
  1015.     char volname[256];
  1016.     
  1017.     volname[0] = len;
  1018.     BlockMove(name, volname+1, len);
  1019.     
  1020.     theParms.ioCompletion = NULL;
  1021.     theParms.ioVRefNum = 0;
  1022.     theParms.ioNamePtr = (StringPtr)volname;
  1023.     theParms.ioWDDirID = 0;
  1024.     theParms.ioWDProcID = 'ERIK';
  1025.     if (IOResult = PBOpenWD(&theParms, FALSE)) /* IM IV pg 158 */
  1026.         {
  1027.         OKStopAlert("Disk may not be on-line, \
  1028. or file may have been moved, deleted, or renamed.");
  1029.         theParms.ioVRefNum = 0;
  1030.         }
  1031.     return(theParms.ioVRefNum);
  1032.     }
  1033.  
  1034.  
  1035. /* The extension functions.*/
  1036.  
  1037. /* InDictionary() returns the general C type
  1038. of a word, according to the following table:
  1039. value    C type
  1040. 0        none - keyword, comment word, local variable, operator etc
  1041. 1        #define or macro name    eg    #define TAB '\t'
  1042. 2        variable name with more than function scope
  1043. 4        function or method name
  1044. 8        enum constant
  1045. 16        typedef name
  1046. 32        struct tag
  1047. 64        union tag
  1048. 128        enum tag
  1049.  
  1050. See hAWK cross-referencing programs for an example of usage. It's unlikely
  1051. that you will be able to provide an equivalent for this function, and
  1052. there’s no great loss if you don’t.
  1053.  */
  1054. short InDictionary(char *tokenName)
  1055.     {
  1056. #if SUPPORT_LEVEL == CUSTOMSUPPORT
  1057.     extern short InMyAppDictionary(char *s);
  1058.     
  1059.     return(InMyAppDictionary(tokenName));
  1060. #else
  1061.     return(0);
  1062. #endif
  1063.     }
  1064.  
  1065. /* This extension function should copy all or the selected part of the
  1066. text in the frontmost window to a Handle. If the front window is not a
  1067. text window, you should try the second-front window - if it isn't text
  1068. either, return NULL. Front OR second front, because a dialog window may be
  1069. the front window at the time - this is the case with hAWK, for example.
  1070. */
  1071. Handle GetFrontText(Boolean getItAll)
  1072.     {
  1073. #if SUPPORT_LEVEL >= BASICTEXT
  1074.     extern Handle MyAppGetFrontText(Boolean getItAll);
  1075.     
  1076.     return(MyAppGetFrontText(getItAll));
  1077. #else
  1078.     return(NULL);
  1079. #endif
  1080.     }
  1081.  
  1082. /* This function should retrieve file names and vRefNums from a one
  1083. or two-dimensional list of files. If *panePtr == -1, you are being asked
  1084. for the first file, otherwise the next file. When there are no more files,
  1085. set *indexPtr = -1. If you have a two-dimensional list, think of panePtr as
  1086. the column index and indexPtr as the row index. For a one-dimensional list,
  1087. use indexPtr to keep track of where you are - just remember to set panePtr to
  1088. something != -1 during the first call. Other than setting panePtr to something
  1089. besides -1 during the first call, and setting indexPtr to -1 when there are
  1090. no more files, you can use them for tracking which file comes next in any way
  1091. you want.
  1092. If you perhaps use full path names, see OpenWorkingDirectoryFromFullName()
  1093. above for hints on how to convert to filename/vRefNum.
  1094. clearFlag TRUE means clear the file from your list; FALSE means leave it in the
  1095. list. Normally FALSE is best - someone might want to reuse the list quite soon,
  1096. as in running two hAWK programs on the same list of files.
  1097. */
  1098. void GetNextMultiFile(short *panePtr, short *indexPtr, 
  1099.             short *vRefNumPtr, char *fileName, Boolean clearFlag)
  1100.     {
  1101. #if SUPPORT_LEVEL == CUSTOMSUPPORT
  1102.     extern void GetNextFileToSearch(short *panePtr, short *indexPtr, 
  1103.         short *vRefNumPtr, char *fileName, Boolean clearFlag);
  1104.     
  1105.     GetNextFileToSearch(panePtr, indexPtr, 
  1106.                 vRefNumPtr, fileName, clearFlag);
  1107. #else
  1108.     *indexPtr = -1;
  1109. #endif
  1110.     }
  1111.  
  1112. /* If you have an alert mechanism with just an OK button that accepts C
  1113. strings, insert it here. Return of 1 means alert was shown and user
  1114. clicked OK, return of 0 means the alert was not shown. If this happens,
  1115. it would be quite OK for your alert function to try to get more memory or
  1116. show an out-of memory alert before returning the 0 or 1. */
  1117. short OKStopAlert(Ptr cstringPtr)
  1118.     {
  1119. #if SUPPORT_LEVEL == CUSTOMSUPPORT
  1120. /* Left in from EnterAct as an example - EnterAct uses FlexAlert(),
  1121. essentially as published in MacTutor Jan '91. As a small refinement, it
  1122. will display an out-of-memory alert if it runs into trouble. FlexAlert
  1123. sizes the alert box to fit the text, and also formats the text nicely. */
  1124.     extern short FlexAlert(short buttonMode, short whichIcon, Ptr csPtr);
  1125. #define JUSTOK    0
  1126. #define STOPICON    0
  1127.     return(FlexAlert(JUSTOK, STOPICON, cstringPtr));
  1128. #else
  1129.     return(0);
  1130. #endif
  1131.     }
  1132.  
  1133. /* Advise the user that memory has run out during code resource execution.
  1134. You must have something for this kicking around in your application - a
  1135. text message is much more likeable than a beep if things fo worng. */
  1136. void MemoryAlert()
  1137.     {
  1138. #if SUPPORT_LEVEL == CUSTOMSUPPORT
  1139.     extern void DoMemoryAlert(short msgNum, long memLimit);
  1140.  
  1141. #define NONELEFT        4
  1142.  
  1143.     DoMemoryAlert(NONELEFT, 0L);
  1144. #else
  1145.     SysBeep(2);
  1146. #endif
  1147.     }
  1148.  
  1149. short GetScreenHeight(void)
  1150.     {
  1151.     return(qd.screenBits.bounds.bottom - qd.screenBits.bounds.top);
  1152.     }
  1153.  
  1154. short GetScreenWidth()
  1155.     {
  1156.     return(qd.screenBits.bounds.right - qd.screenBits.bounds.left);
  1157.     }
  1158.  
  1159. void ShowWatchCursor()
  1160.     {
  1161. #if SUPPORT_LEVEL == CUSTOMSUPPORT
  1162.     extern void MySetWatchCursor(void);
  1163.     
  1164.     MySetWatchCursor();
  1165. #endif
  1166.  
  1167.     /* this goes something like:
  1168.     CursHandle        Watch;
  1169.     Watch = GetCursor(watchCursor); <- ToolboxUtil.h  enum constant --
  1170.     if (Watch)
  1171.         SetCursor (*Watch);
  1172.     else
  1173.         InitCursor();
  1174.     */
  1175.     }
  1176.  
  1177. void DoEventLoopOnce()
  1178.     {
  1179. #if VERSION2 == TRUE
  1180.     extern void HandleOneEvent(void);
  1181.     
  1182.     HandleOneEvent();
  1183. #endif
  1184.     }
  1185.  
  1186. Handle GetAppClip()
  1187.     {
  1188. #if SUPPORT_LEVEL == CUSTOMSUPPORT
  1189. #if VERSION2 == TRUE
  1190.     extern pascal Handle    PEGetScrap(void);
  1191.     return(PEGetScrap());
  1192. #endif
  1193. #endif
  1194.     return(NULL);
  1195.     }
  1196.  
  1197. short PutAppClip(char *newClipStr)
  1198.     {
  1199.     // Put the C string newClipStr on your application's private clip,
  1200.     // as for example make a handle here, put the string in it, and
  1201.     // set TextEdit's scrap to the new handle.
  1202.     // return 0 if failure, 1 if success.
  1203.     return 0;
  1204.     }
  1205.